package com.zzyl.nursing.controller.member;

import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.core.domain.R;
import com.zzyl.common.core.page.TableDataInfo;
import com.zzyl.nursing.domain.Reservation;
import com.zzyl.nursing.dto.ReservationDto;
import com.zzyl.nursing.service.IReservationService;
import com.zzyl.nursing.vo.ReservationCountVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 预约信息Controller
 *
 * @author ruoyi
 */
@RestController
@RequestMapping("/member/reservation")
@Api(tags = "预约信息相关接口")
public class MemberReservationController extends BaseController {

    @Autowired
    private IReservationService reservationService;

    /**
     * 查询取消预约数量
     */
    @GetMapping("/cancelled-count")
    @ApiOperation("查询取消预约数量")
    public R<Long> getCancelledReservationCount() {
        Long count = reservationService.getCancelledReservationCount();
        return R.ok(count);
    }

    /**
     * 查询预约剩余次数
     */
    @GetMapping("/countByTime")
    @ApiOperation("查询预约剩余次数")
    public R<List<ReservationCountVo>> countByTime(@ApiParam(value = "时间戳") Long time) {
        return R.ok(reservationService.countByTime(time));
    }

    /**
     * 新增预约信息
     */
    @PostMapping
    @ApiOperation("新增预约信息")
    public AjaxResult add(@ApiParam("预约信息信息") @RequestBody Reservation reservation) {
        reservationService.insertReservation(reservation);
        return success();
    }

    /**
     * 分页查询预约信息列表
     */
    @GetMapping("/page")
    @ApiOperation("分页查询预约信息列表")
    public R<TableDataInfo<Reservation>> list(@ApiParam("预约信息查询条件") ReservationDto reservationDto) {
        TableDataInfo<Reservation> tableDataInfo = reservationService.selectPage(reservationDto);
        return R.ok(tableDataInfo);
    }

    /**
     * 取消预约
     */
    @ApiOperation("取消预约")
    @PutMapping("/{id}/cancel")
    public AjaxResult cancel(@ApiParam("预约信息ID") @PathVariable("id") Long id) {
        reservationService.cancel(id);
        return success();
    }
}